package com.zmy.xcx.controller;

import com.zmy.xcx.common.convention.result.Result;
import com.zmy.xcx.common.convention.result.Results;
import com.zmy.xcx.pojo.dto.HypertensionSelfCheckDTO;
import com.zmy.xcx.pojo.vo.AdviceVO;
import com.zmy.xcx.pojo.vo.HypertensionMedicationVO;
import com.zmy.xcx.pojo.vo.HypertensionSelfCheckVO;
import com.zmy.xcx.service.HypertensionSelfCheckService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/hypertension")
@RequiredArgsConstructor
public class HypertensionController {
    private final HypertensionSelfCheckService hypertensionSelfCheckService;
    /**
     * 根据openid保存用户年龄
     * @param age
     * @return
     */

    @PostMapping("/ageCheck")
    public Result<Void> saveAgeCheckHypertension(@RequestParam("age" ) Integer age) {
        log.info("参数年龄age:{}", age);
        hypertensionSelfCheckService.saveAgeCheckHypertension(age);
        return Results.success();
    }

    /**
     * 保存用户信息，返回建议
     * @param hypertensionSelfCheckDTO
     * @return
     */
    @PostMapping("/check")
    public Result<List<AdviceVO>> saveCheckHypertension(@RequestBody HypertensionSelfCheckDTO hypertensionSelfCheckDTO) {
        log.info("请求参数hypertensionSelfCheckDTO:{}", hypertensionSelfCheckDTO);
        return Results.success(hypertensionSelfCheckService.saveCheckHypertension(hypertensionSelfCheckDTO));

    }

    /**
     * 获取用户记录
     * @return
     */
    @GetMapping("/history")
    public Result<HypertensionSelfCheckVO> getHistoryHypertension() {
        return Results.success(hypertensionSelfCheckService.getHistoryHypertension());
    }

    /**
     * 获取高血压药物list
     * @return
     */
    @GetMapping("/medicine")
    public Result<List<HypertensionMedicationVO>> getMedicine() {
        return Results.success(hypertensionSelfCheckService.getMedicine());
    }

    /**
     * 点击次数+1
     * @param id
     * @return
     */
    @PostMapping("/medicine/clicks/{id}")
    public Result<Void> addClicks(@PathVariable("id") Integer id) {
        log.info("点击高血压药物id:{}", id);
        hypertensionSelfCheckService.addClicks(id);
        return Results.success();
    }


}
